<?php

class Blog extends BaseModel {
    
    public $table = "blogs";
    
    public $denied_blog_domain = array(
        "admin", "administrator", "guanli", "new", "posts", "houtai", "manage", "fuck"
    );
    
    /**
     * 创建一个博客
     * @param $uid
     * @param $sub_domain
     * @return integer last insert id
     */
    public function create($uid, $sub_domain) {
        if(!preg_match("/[a-z0-9\-]{5,15}/", $sub_domain)) {
            return array("sub_domain", "个性域名格式不对");
        }
        if($this->get_by($sub_domain, "sub_domain") 
                or in_array($sub_domain, $this->denied_blog_domain)) {
            return array("sub_domain", "个性域名已经被使用了");
        }
        
        return $this->insert(array(
            "uid" => $uid,
            "name" => $sub_domain,
            "sub_domain" => $sub_domain
        ));
    }
    
}